library(tidyverse)
library(qualtRics)
library(openxlsx)

# Loading data -----------------------------------
data <- read_survey("Raw Data/study 2_data.csv")
consents <- which(data$Consent_2==1)  
data <- data[consents,]
attention.check1 <- which((data$attention_1_3==1 & data$attention_1_6==1) |
                            (data$attention_warning_3==1 & data$attention_warning_6==1))
attention.check2 <- which(data$attention_2_1==7 |
                            data$attention_warning2_1==7)
data <- data[attention.check2,] 
data$id <- 1:dim(data)[1]


# Adding participant characteristics (not used in study) --------------------------
library(foreign)
chars <- read.spss("Raw Data/study 2_PID V2.sav", to.data.frame=TRUE)
colnames(chars)[2] <- "PID"
chars$PID <- stringr::str_trim(chars$PID) 
data <- left_join(data,chars, by="PID")
data <- data[-which(data$id%in%c(772, 1061)),]# for reasons unclear, these two observations were accidentally removed in the process

data <- data[,c(19:23,63:109,215:223)]
data <- data[complete.cases(data[,53:56]),] # remove missing data but not for vote choice

save(data, file="Data/survey_data.RData")
